Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
Imports DataAccesGenerales
Imports DataAcces

Public Class DataAccesAduana_Multiple_Etiquetado
  Private Const consTimeOut As Integer = 0 

    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
   Public Function Aduana_Multiple_Etiquetado_InsertarModificar(pnidDocumento As Long, pnidAduanamulTiple As Long, pnidAgenciaAduanal As Long, ppatente As String, ppedimento As String, pdescripcion_Mercancia As String, pcantidad As Long, pcontenedor As String, psello As String, ptipo_Etiquetas As String, pretencion As String, pnumero_Pama As String, pnorma As String, pnorma_Campo As String, pnidTipoUnidades As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoInsertarModificar"
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("pnidAduanamulTiple", pnidAduanamulTiple)
          oraCommandDocumentos.Parameters.Add("pnidAgenciaAduanal", pnidAgenciaAduanal)
          oraCommandDocumentos.Parameters.Add("ppatente", ppatente)
          oraCommandDocumentos.Parameters.Add("ppedimento", ppedimento)
          oraCommandDocumentos.Parameters.Add("pdescripcion_Mercancia", pdescripcion_Mercancia)
          oraCommandDocumentos.Parameters.Add("pcantidad", pcantidad)
          oraCommandDocumentos.Parameters.Add("pcontenedor", pcontenedor)
          oraCommandDocumentos.Parameters.Add("psello", psello)
          oraCommandDocumentos.Parameters.Add("ptipo_Etiquetas", ptipo_Etiquetas)
          oraCommandDocumentos.Parameters.Add("pretencion", pretencion)
          oraCommandDocumentos.Parameters.Add("pnumero_Pama", pnumero_Pama)
          oraCommandDocumentos.Parameters.Add("pnorma", pnorma)
          oraCommandDocumentos.Parameters.Add("pnorma_Campo", pnorma_Campo)
          oraCommandDocumentos.Parameters.Add("pnidTipoUnidades", pnidTipoUnidades)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para consultar un registro de la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
    ''' <param name="pNidDocumento">numero de documento</param>
    ''' <returns>DataTable</returns>
    ''' <remarks></remarks>
   Public Function Aduana_Multiple_Etiquetado_Consultar(pNidDocumento As Long) As DataTable
        Dim dtResultado As New DataTable("Aduana_Multiple_EtiquetadoConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoConsultar"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la cadena XML Chilkat del documento de la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
    ''' <param name="nidDocumento"> numero del documento</param>
    ''' <returns>Chilkat.Xml</returns>
    ''' <remarks></remarks>
   Public Function Aduana_Multiple_Etiquetado_CadenaOriginalXMLChilkat(nidDocumento As Long) As Chilkat.Xml
        Dim detalleDataSet As New DataSet("DatosAduana_Multiple_Etiquetado")
        Try
      detalleDataSet = Aduana_Multiple_Etiquetado_DetalleXML(nidDocumento)
            'En esta parte van las tablas obtenidas en la consulta anterior
            'separadas dependiendo del reporte a crear, ejemplo:
            detalleDataSet.Tables(0).TableName = "Informacion del Tramite"
            detalleDataSet.Tables(1).TableName = "Datos Aduana_Multiple_Etiquetado"
            detalleDataSet.Tables(2).TableName = "Archivos Anexos"
            detalleDataSet.Tables(3).TableName = "Incidencias"

            Dim xml As New Chilkat.Xml
            xml.LoadXml(detalleDataSet.GetXml())
            Return xml 'detalleDataSet.GetXml()
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' Funcion para consultar el detalle del documento de la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>DataSet</returns>
    ''' <remarks></remarks>
   Public Function Aduana_Multiple_Etiquetado_DetalleXML(pNidDocumento As Long) As DataSet
        Dim dsDetalle As New DataSet("Aduana_Multiple_EtiquetadoDetalle")
        Dim pTransaccion As Byte = 0
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoDetalleXML"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    'En esta parte es para los cursores necesario 
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pEncabezado", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pDatos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pAnexos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pIncidencias", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    'pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraDataAdapter.Fill(dsDetalle)
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dsDetalle
    End Function
  
   Public Function Aduana_Multiple_Etiquetado_DatosBase() As DataTable
        Dim dtResultado As New DataTable("Aduana_Multiple_EtiquetadoConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoDatosBase"
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
   Public Function Aduana_Multiple_Etiquetado_Insertar(pnidDocumento As Long, pnidAduanamulTiple As Long, pnidAgenciaAduanal As Long, ppatente As String, ppedimento As String, pdescripcion_Mercancia As String, pcantidad As Long, pcontenedor As String, psello As String, ptipo_Etiquetas As String, pretencion As String, pnumero_Pama As String, pnorma As String, pnorma_Campo As String, pnidTipoUnidades As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoInsertar"
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("pnidAduanamulTiple", pnidAduanamulTiple)
          oraCommandDocumentos.Parameters.Add("pnidAgenciaAduanal", pnidAgenciaAduanal)
          oraCommandDocumentos.Parameters.Add("ppatente", ppatente)
          oraCommandDocumentos.Parameters.Add("ppedimento", ppedimento)
          oraCommandDocumentos.Parameters.Add("pdescripcion_Mercancia", pdescripcion_Mercancia)
          oraCommandDocumentos.Parameters.Add("pcantidad", pcantidad)
          oraCommandDocumentos.Parameters.Add("pcontenedor", pcontenedor)
          oraCommandDocumentos.Parameters.Add("psello", psello)
          oraCommandDocumentos.Parameters.Add("ptipo_Etiquetas", ptipo_Etiquetas)
          oraCommandDocumentos.Parameters.Add("pretencion", pretencion)
          oraCommandDocumentos.Parameters.Add("pnumero_Pama", pnumero_Pama)
          oraCommandDocumentos.Parameters.Add("pnorma", pnorma)
          oraCommandDocumentos.Parameters.Add("pnorma_Campo", pnorma_Campo)
          oraCommandDocumentos.Parameters.Add("pnidTipoUnidades", pnidTipoUnidades)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function

    ''' <summary>
    ''' Funcion para Modificar un regristro en la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
   Public Function Aduana_Multiple_Etiquetado_Modificar(pnidDocumento As Long, pnidAduanamulTiple As Long, pnidAgenciaAduanal As Long, ppatente As String, ppedimento As String, pdescripcion_Mercancia As String, pcantidad As Long, pcontenedor As String, psello As String, ptipo_Etiquetas As String, pretencion As String, pnumero_Pama As String, pnorma As String, pnorma_Campo As String, pnidTipoUnidades As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoModificar"
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("pnidAduanamulTiple", pnidAduanamulTiple)
          oraCommandDocumentos.Parameters.Add("pnidAgenciaAduanal", pnidAgenciaAduanal)
          oraCommandDocumentos.Parameters.Add("ppatente", ppatente)
          oraCommandDocumentos.Parameters.Add("ppedimento", ppedimento)
          oraCommandDocumentos.Parameters.Add("pdescripcion_Mercancia", pdescripcion_Mercancia)
          oraCommandDocumentos.Parameters.Add("pcantidad", pcantidad)
          oraCommandDocumentos.Parameters.Add("pcontenedor", pcontenedor)
          oraCommandDocumentos.Parameters.Add("psello", psello)
          oraCommandDocumentos.Parameters.Add("ptipo_Etiquetas", ptipo_Etiquetas)
          oraCommandDocumentos.Parameters.Add("pretencion", pretencion)
          oraCommandDocumentos.Parameters.Add("pnumero_Pama", pnumero_Pama)
          oraCommandDocumentos.Parameters.Add("pnorma", pnorma)
          oraCommandDocumentos.Parameters.Add("pnorma_Campo", pnorma_Campo)
          oraCommandDocumentos.Parameters.Add("pnidTipoUnidades", pnidTipoUnidades)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para generar un combo de la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
    ''' <param name="pNombre">nombre a buscar en la tabla</param>
    ''' <returns>DataTable</returns>
    ''' <remarks>si el nombre es "" retornara todos los registros</remarks>
   Public Function Aduana_Multiple_Etiquetado_Combo(pNombre As String) As DataTable
        Dim dtResultado As New DataTable("Aduana_Multiple_EtiquetadoCombo")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoCombo"
                    oraCommandDocumentos.Parameters.Add("pNombre", pNombre)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la integracion del documento de la tabla Aduana_Multiple_Etiquetado
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>Byte</returns>
    ''' <remarks></remarks>
   Public Function Aduana_Multiple_Etiquetado_Integracion(pNidDocumento As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoIntegracion"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
   Public Function Aduana_Multiple_Etiquetado_Borrar(pnid As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Aduana_Multiple_EtiquetadoBorrar"
                    oraCommandDocumentos.Parameters.Add("pnid", pnid)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
  
End Class
